public class Solution2 {
    public boolean[][] row;
    public boolean[][] col;
    public boolean[][][] grid;

    public boolean isValidSudoku(char[][] board) {
        row = new boolean[9][10];
        col = new boolean[9][10];
        grid = new boolean[3][3][10];

        for(int i = 0; i < 9; i++) {
            for(int j = 0; j < 9; j++) {
                if(board[i][j] != '.') {
                    int num = board[i][j] - '0';
                    // 判断是否有效
                    if(row[i][num] == true) {
                        return false;
                    }
                    row[i][num] = true;
                    if(col[j][num] == true) {
                        return false;
                    }
                    col[j][num] = true;
                    if(grid[i / 3][j / 3][num] == true) {
                        return false;
                    }
                    grid[i / 3][j / 3][num] = true;
                }
            }
        }
        return true;
    }
}
